package com.tshopping.service.impl;

import com.tshopping.bean.Parameter;
import com.tshopping.dao.ParameterDao;
import com.tshopping.service.ParameterService;
import com.tshopping.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;

/**
 * @name: ParameterServiceImpl
 * @description: 商品参数业务层类
 * @author: Jackeys
 * @date: 2021-01-23 22:12
 */
@Service(value = "parameterService")
@Transactional
public class ParameterServiceImpl implements ParameterService {

    @Autowired
    private ParameterDao parameterDao;

    @Override
    /**
     * @description 处理用户添加商品参数
     * @Param: stock
     * @Param: specification
     * @Param: goods
     * @Param: color
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-23 22:15
     */
    public ResponseData addParameter(int stock, String specification, int goods, String color) {
        ResponseData responseData=ResponseData.ok();
        responseData.putDataValue("flag",parameterDao.insertParameterByParameterInformation(stock, specification, goods, color));
        return responseData;
    }

    @Override
    /**
     * @description 处理用户修改参数
     * @Param: stock
     * @Param: specification
     * @Param: color
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-23 22:16
     */
    public ResponseData updateParameter(int stock, String specification, String color, int id) {
        ResponseData responseData=ResponseData.ok();
        responseData.putDataValue("flag",parameterDao.updateGoodsParameterByParameterId(stock, specification, color, id));
        return responseData;
    }

    @Override
    /**
     * @description 处理用户获取商品参数
     * @Param: goods
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-23 22:16
     */
    public ResponseData getParameters(int goods) {
        ResponseData responseData=ResponseData.ok();
        responseData.putDataValue("parameterList",parameterDao.selectParametersByGoodsId(goods));
        return responseData;
    }

    @Override
    /**
     * @description 处理用户删除参数
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-23 22:17
     */
    public ResponseData deleteParameters(int id) {
        ResponseData responseData=ResponseData.ok();
        responseData.putDataValue("flag",parameterDao.deleteParameterByParameterId(id));
        return responseData;
    }
}
